<?php
// $Id$

/**
 * @file
 * TODO
 */

function _portals_list_all() {
  $all_portals = _portals_sql_get_all_portal_ids();
  $output = array();
  if ($all_portals != -1) {
    $output = array();
    foreach ($all_portals as $portal_name => $portal_config) {
      if (!empty($portal_config)) {
        $items = array();
        foreach ($portal_config as $portal_item) {
          $args = $portal_item->args;
          if ($portal_item->type == 'block') {
            $items[] = array('block', array($args[0], $args[1]));
          }
          elseif ($portal_item->type == 'page') {
            $items[] = array('page', array($args[0]));
          }
        }
      }
      $output[$portal_name] = $items;
    }
  }
  return theme('portals_list', $output);
}


function _portals_sql_get_all_portal_ids() {
  $get_the_pid_from_nme = db_query(
   "SELECT p.nme, p.cnf
    FROM {portals} p"
  );
  $results = array();
  while ($pid_result_object = db_fetch_object($get_the_pid_from_nme)) {
    $results[$pid_result_object->nme] = unserialize($pid_result_object->cnf);
  }
  if (!empty($results)) {
    return $results;
  }
  else {
    return -1;
  }
}


function _portals_get_contents($portal_name) {
  portals_include('queries');
  $portal_id = _portals_node_portal_portalid_from_name($portal_name);
  if ($portal_id != -1) {
    $page_content = "Portal $portal_name has the following configuration.<br /><br />"; 
    foreach (_portals_get_cnf_from_pid($portal_id) as $config_item) { 
      $page_content .= $config_item->type .',';
      $page_content .= implode($config_item->args, ',') .'<br />';
    }
  }
  else {
    $page_content = "A portal with the name '$portal_name' does not exist in the database.";
  }
  return $page_content;
}